// filename: VisibleRect.cpp
// author: enic
// date: 2016-03-12

#pragma once

#include "cocos2d.h"

#include "VisibleRect.h"

namespace EZFY
{

	cocos2d::Rect VisibleRect::ms_visibleRect;

	cocos2d::Rect VisibleRect::getVisibleRect()
	{
		lazyInit();

		return cocos2d::Rect(ms_visibleRect.origin.x, ms_visibleRect.origin.y,
			ms_visibleRect.size.width, ms_visibleRect.size.height);
	}

	cocos2d::Point VisibleRect::left()
	{
		lazyInit();

		return cocos2d::Point(ms_visibleRect.origin.x, ms_visibleRect.origin.y + ms_visibleRect.size.height / 2);
	}

	cocos2d::Point VisibleRect::right()
	{
		lazyInit();

		return cocos2d::Point(ms_visibleRect.origin.x, ms_visibleRect.origin.y + ms_visibleRect.size.height / 2);
	}

	cocos2d::Point VisibleRect::top()
	{
		lazyInit();
		return cocos2d::Point(ms_visibleRect.origin.x + ms_visibleRect.size.width / 2, ms_visibleRect.origin.y + ms_visibleRect.size.height);
	}

	cocos2d::Point VisibleRect::bottom()
	{
		lazyInit();
		return cocos2d::Point(ms_visibleRect.origin.x + ms_visibleRect.size.width / 2, ms_visibleRect.origin.y);
	}

	cocos2d::Point VisibleRect::center()
	{
		lazyInit();
		return cocos2d::Point(ms_visibleRect.origin.x + ms_visibleRect.size.width / 2,
			ms_visibleRect.origin.y + ms_visibleRect.size.height / 2);
	}

	cocos2d::Point VisibleRect::leftTop()
	{
		lazyInit();
		return cocos2d::Point(ms_visibleRect.origin.x, ms_visibleRect.origin.y + ms_visibleRect.size.height);
	}

	cocos2d::Point VisibleRect::rightTop()
	{
		lazyInit();
		return cocos2d::Point(ms_visibleRect.origin.x + ms_visibleRect.size.width, ms_visibleRect.origin.y + ms_visibleRect.size.height);
	}

	cocos2d::Point VisibleRect::leftBottom()
	{
		lazyInit();
		return ms_visibleRect.origin;
	}

	cocos2d::Point VisibleRect::rightBottom()
	{
		lazyInit();
		return cocos2d::Point(ms_visibleRect.origin.x + ms_visibleRect.size.width, ms_visibleRect.origin.y);
	}

	void VisibleRect::lazyInit()
	{
		if (ms_visibleRect.size.width == 0.0f && ms_visibleRect.size.height == 0.0f)
		{
			ms_visibleRect.origin = cocos2d::Director::getInstance()->getVisibleOrigin();
			ms_visibleRect.size = cocos2d::Director::getInstance()->getVisibleSize();
		}
	}

	


}